<div class="container">
  <div class="title-desc">
      <h2>User</h2>
    <span>Manage the user account registration and access (<a href="https://docs.opencatapult.net/home/concept#user-account" target="_blank">more...</a>)</span>
  </div>
  <div fxLayout="row" fxLayoutAlign="space-between center">
    <div>
        <mat-select placeholder="User Status"
          (selectionChange)="onStatusFilterChanged()" [formControl]="statusFilter">
          <mat-option *ngFor="let status of userStatus" [value]="status.value">
            {{status.text}}
          </mat-option>
        </mat-select>
    </div>
    <div class="action-buttons">
      <button mat-raised-button (click)="onRegisterUserClick()">Register New User</button>
    </div>
  </div>
  <app-loading-spinner *ngIf="loading"></app-loading-spinner>
  <div *ngIf="!loading">
    <div class="no-records" *ngIf="users?.length <= 0">
      No Users Found
    </div>

    <table mat-table [dataSource]="users" matSort *ngIf="users?.length > 0" class="mat-elevation-z8">

      <!--- Note that these columns can be defined in any order.
            The actual rendered columns are set as a property on the row definition" -->

      <!-- userName Column -->
      <ng-container matColumnDef="userName">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> Username </th>
        <td mat-cell *matCellDef="let element"> {{element.userName}} </td>
      </ng-container>

      <!-- email Column -->
      <ng-container matColumnDef="email">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> Email </th>
        <td mat-cell *matCellDef="let element"> {{element.email}} </td>
      </ng-container>

      <!-- firstName Column -->
      <ng-container matColumnDef="firstName">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> First Name </th>
        <td mat-cell *matCellDef="let element"> {{element.firstName}} </td>
      </ng-container>

      <!-- lastName Column -->
      <ng-container matColumnDef="lastName">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> Last Name </th>
        <td mat-cell *matCellDef="let element"> {{element.lastName}} </td>
      </ng-container>

      <!-- role Column -->
      <ng-container matColumnDef="role">
        <th mat-header-cell *matHeaderCellDef mat-sort-header appHelpElement="User" subSection="User Role"> Role </th>
        <td mat-cell *matCellDef="let element"> {{element.role}} </td>
      </ng-container>

      <!-- emailConfirmed Column -->
      <ng-container matColumnDef="emailConfirmed">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> Email Confirmed? </th>
        <td mat-cell *matCellDef="let element"> {{element.emailConfirmed ? 'Yes' : 'No'}} </td>
      </ng-container>

      <!-- Action Column -->
      <ng-container matColumnDef="actions">
        <th mat-header-cell *matHeaderCellDef> </th>
        <td mat-cell *matCellDef="let element" class="item-buttons">
          <button mat-icon-button (click)="onInfoClick(element)" matTooltip="Info">
            <mat-icon>info</mat-icon>
          </button>
          <button mat-icon-button (click)="onSetRoleClick(element)" matTooltip="Set User Role">
            <mat-icon>how_to_reg</mat-icon>
          </button>
          <button mat-icon-button (click)="onSuspendClick(element)" matTooltip="Suspend" *ngIf="statusFilter.value === 'active'">
            <mat-icon>block</mat-icon>
          </button>
          <button mat-icon-button (click)="onActivateClick(element)" matTooltip="Activate" *ngIf="statusFilter.value === 'suspended'">
            <mat-icon>unarchive</mat-icon>
          </button>
          <button mat-icon-button  matTooltip="Delete" (click)="onDeleteClick(element)">
            <mat-icon>delete</mat-icon>
          </button>
        </td>
      </ng-container>

      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    </table>
  </div>
</div>
